<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>预付款页面</title>
    <jsp:include page=".././../head.jsp"/>
    <script type="application/javascript" src="/js/jquery.timers-1.2.js"></script>
    <script type="text/javascript">
        function clearNoNum(obj)
        {
            obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        }
        function getQRcode(payChannel){
            if(!payChannel){
                $("#returnMsg").html("预付款出错，请联系管理员！");
                return;
            }
            var totalAmount=$("#amount").val();
            if(!totalAmount || parseFloat(totalAmount)==0){
                $("#returnMsg").html("请输入预付款金额！");
                return;
            }
            $.ajax({
                       type: "GET",
                       url: "/fund/getQRcode",
                       data: {payChannel:payChannel, orderNo:getQRcode.serialNumber[payChannel], totalAmount:totalAmount},
                       dataType: "json",
                       success: function(data){
                           getQRcode.serialNumber[payChannel] = data["outTradeNo"];
                           if(data && data.qrUrl){
                                $("#qrCodeUrl").attr("src",data.qrUrl);
                                $("#qrCodeUrl").attr("alt",payChannel=='1'?"微信":"支付宝");
                                $("#qrCodeUrl").attr("title",payChannel=='1'?"微信":"支付宝");
                                $("#returnMsg").html(data.returnMsg);
                               $("input[name='bid']").val(data.outTradeNo);
                           }else{
                               $("#qrCodeUrl").attr("src","");
                               $("#qrCodeUrl").attr("alt","");
                               $("#qrCodeUrl").attr("title","");
                               $("#returnMsg").html(data.returnMsg);
                               $("input[name='bid']").val("");
                           }
                       }
                   });
        }
        getQRcode.serialNumber={"0":"", "1":""};


        function gotoUnionPay(){
            var amount=$("#amount").val();
            if(!amount){
                alert("请输入金额！");
                return;
            }
            $("input[name='state']").val("INIT");
            $("input[name='fundPayType']").val("ONLINE");
            $.ajax({
                       url:"ajustment-saveOrUpdate",
                       type:"post",
                       data:$("#payForm").serialize(),
                       success: function (data) {
                           try {
                               var jr = JSON.parse(data.data);
                               if ("undefined" != typeof jr && "undefined" != typeof jr.purl) {
                                   window.open(jr.purl);
                               }
                           } catch (e) {
                           }
                           location.href = 'ajustment-main';
                       }
                   });
        }
        $(document).ready(function () {
            $('body').everyTime('1s',function(){
                var bid=$("input[name='bid']").val();
                if(bid){
                    $.ajax({
                               url:"getPaymentResult",
                               type:"post",
                               data:{"orderNo":bid},
                               success: function (data) {
                                   if(data=="SUCCESS"){
                                       location.href = 'paySuccess';
                                   }
                               }
                           });
                }
            });
        });

    </script>
</head>
<body>
<div align="center">
    <form id="payForm">
        <input type="hidden" name="fundPayType">
<table width="100%" border="0" style="line-height: 7em;margin-left: 30px;">
    <tr>
        <td width="100px">预付款编号</td>
        <td width="200px"><input type="text" readonly="readonly" name="bid"></td>
        <td width="100px">支付编号</td>
        <td width="200px"><input type="text" readonly="readonly"></td>
        <td rowspan="4" align="center"><img id="qrCodeUrl" name="qrCodeUrl" alt="" width="200px" height="auto"><div id="returnMsg"></div></td>
    </tr>
    <tr>
        <td width="100px">状态</td>
        <td width="200px"><input type="text" name="state" readonly="readonly"></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td width="100px">金额</td>
        <td width="200px"><input type="text" id="amount" name="amount" onkeyup="clearNoNum(this);"></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td onclick="gotoUnionPay();"><img src="/img/visa.jpg" alt="银联" title="银联" width="100px" height="auto"></td>
        <td align="center" onclick="getQRcode(2);"><img src="/img/zhifubao.jpg" alt="支付宝" title="支付宝" width="100px" height="auto"></td>
        <td onclick="getQRcode(1);"><img src="/img/weixinIcon.jpg" alt="微信支付" title="微信支付" width="100px" height="auto"></td>
        <td></td>
    </tr>
</table>
    </form>
</div>
<fieldset class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
        <a
                href="javascript:void(0)"
                class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
            class="replace-ui-jqgrid-title">预付款说明</span>
    </div>
    <p> 请填写预付款金额，金额精确到小数点后2位。</p>
    <p> 在线预付款到账需要一定时间，请耐心等候。 </p>
    <p> 重新支付将丢失当前的支付编号记录，请谨慎操作，如对预付款状态有疑问，请咨询平台客服人员。 </p>
    <p><br/></p>
</fieldset>
</body>
</html>